import os

import pandas as pd


file_config = {
    "公募基金-基金日净值文件.csv": {
        "output": "fund_daily.pkl",
        "converters": None,
        "rename": {
            "基金代码": "fundid",
            "交易日期": "date",
            "accumulative基金份额净值": "accnav",
        },
        "keeping": ["date", "fundid", "accnav"],
    }
}

cur_dir = os.path.dirname(__file__)
all_files = os.listdir(cur_dir)
for file in all_files:
    if file.endswith(".csv"):
        data = pd.read_csv(
            os.path.join(cur_dir, file), converters=file_config[file]["converters"]
        )
        if "rename" in file_config[file].keys():
            data.rename(columns=file_config[file]["rename"], inplace=True)
        if "keeping" in file_config[file].keys():
            data = data[file_config[file]["keeping"]]
        data.to_pickle(os.path.join(cur_dir, file_config[file]["output"]), "gzip")
